#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QLibrary>
#include <QSqlQuery>
#include <QThread>
#include <QTimer>
#include <QNetworkRequest>
#include <QNetworkInterface>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QTcpSocket>
#include <QTcpServer>
#include <QFile>
#include "threadyb.h"       //医保线程

#include "com_re_signin.h" //变更登录身份

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    QThread thread;
    ThreadYb *ybBusiness;

    void ybSign();

protected:
    void closeEvent(QCloseEvent *event);

public slots:

    void re_signin();
    void close_windows(QString mode = "");

    void reg_trigged();
    void exit_trigged();
    void action_func_test_trigged();
    void action_ghsz_trigged();
    void action_cfdy_trigged();
    void actionDrugItems_trigged();
    void action_drugQuery_trigged();
    void action_sk_trigged();
    void action_tf_trigged();
    void action_changePass_trigged();
    void action_gzltj_trigged();
    void action_cftj_trigged();
    void action_jcmlxz_trigged();
    void action_xmdz_trigged();
    void action_xxcx_trigged();
    void action_jsdz_trigged();
    void action_dzbl_trigged();
    void action_ybhj_trigged();
    void action_recipe_manage_trigged();
    void action_InOut_trigged();
    void action_qlsjsc_trigged();
    void action_yk_rk_trigged();
    void action_ys_bzgl_trigged();
    void action_ys_env_trigged();
    void action_com_jbgl_trigged();
    void action_tj_ybxmcx_trigged();
    void action_user_trigged();
    void action_kccx_trigged();
    void action_dept_trigged();
    void action_ys_sfgl_trigged();
    void action_undrug_trigged();
    void action_recipe_check_trigged();
    void action_patient_detail_trigged();
    void action_fin_base_trigged();
    void action_data_dump_trigged();
    void action_lab_main_trigged();
    void action_re_login_trigged();
    void action_mat_io_trigged();
    void action_mat_query_trigged();
    void action_log_browse_trigged();
    void action_tj_drug_consume_dept_trigged();
    void action_physio_trigged();
    void action_senior_reci_ck_trigged();
    void action_yk_baseitem_trigged();
    void action_purchase_plan_trigged();


    void handleInitial(const int, const QString, const QString );
    //void handleSignIn(const int, const QString );
    void updateTitle(); //定时，显示title
    void waitInitFinish();//定时，等待卡初始化完成

    void postRequestFinished(QNetworkReply *);

    void destroyWind( QString );
    void update_local_datetime(QString);

    void send_file_chunk();//qint64
    void tcp_connect_timeout();
    void accept_connection();

    bool manipulate_query(QJsonObject);
    void read_client_data();

signals:
    void opThread(int, QString);    // 发送信号触发线程


private:
    Ui::MainWindow *ui;
    QLibrary lib;
    QSqlQuery qrm;
    QSqlQuery qro;
    QTimer *tm, *tm2, *tm_log, *tm_tcp;

    Com_re_signin * com_re_signin; //变更登录身份


    volatile bool httpFinished;
    volatile bool initFinished;
    QString currentInfno;
    bool ybSigned ;
    QNetworkReply * rpl ;
    QNetworkRequest request;
    QNetworkAccessManager* naManager;

    QString currentMsgid;

    QMap<QString, QWidget *> forms;  //全部窗口的容器

    QTcpServer *tcp_server;
    QTcpSocket *tcp_socket;
    QTimer *tm_receive;


    QFile file;
    //QString selectedFile;
    QString fileName;
    qint64 fileSize;
    qint64 bytesToSend;
    qint64 bytesWritten;

    //QStringList log_file_list;


};
#endif // MAINWINDOW_H
